package main

import (
	"baize/app/baize"
	"baize/app/business/system/systemModels"
	"baize/app/datasource"
	"baize/app/setting"
	"context"
	"fmt"
	"go.mongodb.org/mongo-driver/mongo"
)

var be = baize.BaseEntity{CreateBy: 1, CreateName: "baize", CreateTime: baize.NewTime(), UpdateBy: 1, UpdateName: "baize", UpdateTime: baize.NewTime()}

func main() {
	ctx := context.Background()
	client, _, err := datasource.NewData(setting.Conf.Mongo)
	if err != nil {
		panic(err)
	}

	Inserts(ctx, client)
	fmt.Println("运行完成")
}

func Inserts(ctx context.Context, client *mongo.Client) {

	//InsertDict(ctx, client)
	InsertUser(ctx, client)
	//InsertRole(ctx, client)
	//InsertSysMenu(ctx, client)

}

func InsertUser(c context.Context, m *mongo.Client) {
	collection := m.Database(datasource.SysDatabase).Collection(datasource.Collection["user"])
	users := make([]interface{}, 0)
	users = append(users, &systemModels.User{UserId: 1, UserName: "admin", CompanyId: 1, CompanyIdAbbreviate: "1", Status: "0", Password: "$2a$14$kOhr1gqDAGYara15BrSuLuI7uzOC7gfAyzJGiLsypO32mEb6O02LO", DeptId: 1, NickName: "baize", DataScope: "1", RoleIds: []int64{1}, BaseEntity: be})
	users = append(users, &systemModels.User{UserId: 2, UserName: "baize", CompanyId: 2, CompanyIdAbbreviate: "2", Status: "0", Password: "$2a$14$kOhr1gqDAGYara15BrSuLuI7uzOC7gfAyzJGiLsypO32mEb6O02LO", BaseEntity: be})
	_, err := collection.InsertMany(c, users)
	if err != nil {
		panic(err)
	}
}
func InsertRole(c context.Context, m *mongo.Client) {
	collection := m.Database("1").Collection(datasource.Collection["role"])
	roles := make([]interface{}, 0)
	roles = append(roles, &systemModels.Role{RoleId: 1, RoleName: "admin", RoleSort: 1, Status: "0", Remake: "", BaseEntity: be})
	_, err := collection.InsertMany(c, roles)
	if err != nil {
		panic(err)
	}
}
